const BaseToString = require('')
/**
 * 创建数学运算
 * @param { Function } operation 运算规则
 * @param { * } defaultValue 默认结果
 * @returns 函数
 *  {
 *    1.判断数据是否存在
 *  }
 *
 */
const createMathOperation = function(operation, defaultValue) {
  return function(value, other) {
    let result;
    if(typeof value === 'undefined' && typeof other === 'undefined') {
      return defaultValue
    }
    if(value !== undefined) {
      result = value
    }
    if(other !== undefined) {
      if(typeof value === 'undefined') {
        result = other
      }
      if(typeof value === 'string' || typeof other === 'string') {
        value = BaseToString(value)
        other = BaseToString(other)
      } else {
        value = BaseToNumber(value)
        other = BaseToNumber(other)
      }
      result = operation(value, other)
    }
    return result
  }
}

module.exports = createMathOperation